var gulp=require("gulp");
// var livereload=require("gulp-livereload");
// var webserver=require("gulp-webserver");
var sass=require("gulp-ruby-sass");
var uglify = require("gulp-uglify");
var rename=require("gulp-rename");

gulp.task("shuaxin",function () {
    return gulp.src("dist")
        .pipe(webserver({
            livereload:true,
            open:true
        }))
})

//移动
gulp.task("movefile",function () {
    return gulp.src("src/**/*.{html,png,jpg,gif,icon,jpeg,js}")
        .pipe(gulp.dest("dist"))
})

//编译sass   gulp-ruby-sass
gulp.task("sass",function () {
    return sass("src/sass/*.scss",{style:"compressed"})
        .on("error",function (err) {
            console.log("sass文件错误");
            console.log(err)
        })
        .pipe(gulp.dest("dist/css"))
})

//压缩js文件 gulp-uglify
// gulp.task("js",function () {
//     return gulp.src("src/js/*.js")
//         .pipe(uglify())
//         .pipe(gulp.dest("dest/js"))
// })
//重命名
gulp.task("rename",function () {
    return gulp.src("src/js/*.js")
        .pipe(rename({suffix:".min"}))
        .pipe(uglify())
        .pipe(gulp.dest("dist/js"))
})

// 监听
gulp.task("watch",function () {
    gulp.watch("src/**/*.{html,png,jpg,gif,icon,jpeg,js,css}",["movefile"]);
    gulp.watch("src/sass/*.scss",["sass"]);
    // gulp.watch("src/js/*.js",["js"]);
    // gulp.watch("src/js/*.js",["rename"]);
});

//默认
gulp.task("default",["movefile","sass","watch","shuaxin"]);

